package service;
import webServlets.publicValue;
import domain.Account;
import persistence.impl.AccountDAOImpl;
import persistence.AccountDAO;

public class AccountService {
    private AccountDAO accountDAO;

    public AccountService() {
        accountDAO = new AccountDAOImpl();
    }

    public Account getAccount(String username) {
        return accountDAO.getAccountByUsername(username);
    }

    public Account getAccount(String username, String password) {
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return accountDAO.getAccountByUsernameAndPassword(account);
    }

    public void insertAccount(Account account) {
        System.out.println("插入到Account");
        accountDAO.insertAccount(account);
        System.out.println("插入到profile");
        accountDAO.insertProfile(account);
        System.out.println("插入到signon");
        accountDAO.insertSignon(account);
        System.out.println("插入成功啦");
    }

    public void updateAccount(Account account) {
        accountDAO.updateAccount(account);
        accountDAO.updateProfile(account);

        if (account.getPassword() != null && account.getPassword().length() > 0) {
            accountDAO.updateSignon(account);
        }
    }

    public boolean isLogIn(){
        if(publicValue.username == ""){
            return false;
        }else {
            return true;
        }
    }


}
